package ModelLayer;


/**
 * Write a description of class Copy here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Copy
{
    private int id;
    private String serialNumber;
    private String purchaseDate;
    private double purchasePrice;
    private boolean available;
    private Person reserved;
    
    public Copy(int id, String serialNumber, String purchaseDate, double purchasePrice)
    {
        this.id = id;
        this.serialNumber = serialNumber;
        this.purchaseDate = purchaseDate;
        this.purchasePrice = purchasePrice;
        available = true;
        reserved = null;
    }
    
    public void setSerialNumber(String inSerialNumber)
    {
        serialNumber = inSerialNumber;
    }
    
    public void setPurchaseDate(String inPurchaseDate)
    {
        purchaseDate = inPurchaseDate;
    }
    
    public void setPurchasePrice(double inPurchasePrice)
    {
        purchasePrice = inPurchasePrice;
    }
    
    public String getSerialNumber()
    {
        return serialNumber;
    }
    
    public String getPurchaseDate()
    {
        return purchaseDate;
    }
    
    public double getPurchasePrice()
    {
        return purchasePrice;
    }
    public void lendCopy()
    {
        available = false;
    }
    
    public void returnCopy()
    {
        available = true;
    }
    
    public boolean isAvailable()
    {
        return available;
    }
    
    public int getId()
    {
        return id;
    }
    
    public boolean isReserved()
    {
        if(reserved == null)
        {return false;
        }
        else
        {
            return true;
        }
    }
    
    public Person toWhom()
    {
        return reserved;
    }
    
    public void reserve(Person person)
    {
        reserved = person;
    }
    
    public void unreserve()
    {
        reserved = null;
    }
    
    /**
     * This method a changes boolean variable into a decent output
     */
    private String avabilityPrint()
    {
        if (available)
        {
            return "Available";
        }
        return "Unavailable";
    }
    
    /**
     * This method changes a class variable into a decent output.
     */
    private String reservedPrint()
    {
        if(reserved == null)
        {
            return "No one";
        }
        return reserved.getName() +" (ID: " + reserved.getId() + ")";
    }
    
    /**
     * This method prints all of the copy's information.
     */
    public void printOut()
    {
        System.out.println("\nID:\t\t\t" + id);
        System.out.println("Serial number:\t\t" + serialNumber);
        System.out.println("Purchase date:\t\t" + purchaseDate);
        System.out.println("Purchase price:\t\t" + purchasePrice);
        System.out.println("Is:\t\t\t" + avabilityPrint());
        System.out.println("Reserved by:\t\t" + reservedPrint());
    }
}
